home *** CD-ROM | disk | FTP | other *** search
/ Risc World 3 / Risc World 3.iso / SOFTWARE / ISSUE6 / PD / PDF / DrawFile / c++ / DrawFileParser next >
Text File  |  2003-02-14  |  4KB  |  96 lines

  1. //--------------------------------------------------------------------------
  2. //
  3. //   Copyright (c) 2002, Colin Granville
  4. //
  5. //   All rights reserved.
  6. //
  7. //   Redistribution and use in source and binary forms, with or
  8. //   without modification, are permitted provided that the following 
  9. //   conditions are met:
  10. //
  11. //      * Redistributions of source code must retain the above copyright 
  12. //        notice, this list of conditions and the following disclaimer.
  13. //
  14. //      * Redistributions in binary form must reproduce the above 
  15. //        copyright notice, this list of conditions and the following 
  16. //        disclaimer in the documentation and/or other materials 
  17. //        provided with the distribution.
  18. //
  19. //      * The name Colin Granville may not be used to endorse or promote 
  20. //        products derived from this software without specific prior 
  21. //        written permission.
  22. //
  23. //   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 
  24. //   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 
  25. //   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 
  26. //   FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 
  27. //   COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 
  28. //   INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 
  29. //   (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 
  30. //   SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 
  31. //   HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 
  32. //   STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
  33. //   ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 
  34. //   OF THE POSSIBILITY OF SUCH DAMAGE.
  35. //
  36. //--------------------------------------------------------------------------
  37.  
  38. #include "GuiBBox.h"
  39. #include "GuiLib:File.h"
  40. #include <iostream.h>
  41. #include <time.h>
  42. #include <stdlib.h>
  43. #include "DrawFileVisitor.h"
  44. #include "DrawFileParser.h"
  45.  
  46.  
  47. int DrawFileParser::accept(DrawFileVisitor& visitor)
  48. {
  49.   visitor.fileHeader(0);
  50.   iterate(visitor,sizeof(DrawFileVisitor::FileHeader),getSize());
  51.   return 0;
  52. }
  53.  
  54. //*********************************************************************
  55.  
  56. int DrawFileParser::iterate(DrawFileVisitor& visitor, size_t start,size_t end)
  57. {
  58.   while (start<end)
  59.   {
  60.     DrawFileVisitor::ObjectHeader* data=(DrawFileVisitor::ObjectHeader*)getObject(start);
  61.     size_t size=data->size;
  62.     size_t next=start+size;
  63.     switch (data->objectType)
  64.     {
  65.        case 12: if (!visitor.transformedTextObject(start)) return 0;
  66.                 break;
  67.        case 2:  if (!visitor.pathObject(start)) return 0;
  68.                 break;
  69.        case 13: if (!visitor.transformedSpriteObject(start)) return 0;
  70.                 break;
  71.        case 1:  if (!visitor.textObject(start)) return 0;
  72.                 break;
  73.        case 5:  if (!visitor.spriteObject(start)) return 0;
  74.                 break;
  75.        case 6:  if (!visitor.enteringGroupObject(start)) return 0;
  76.                 if (!iterate(visitor,start+sizeof(DrawFileVisitor::GroupObject),next)||
  77.                     !visitor.leavingGroupObject(start)) return 0;
  78.                 break;
  79.        case 7:  if (!visitor.taggedObject(start)) return 0;
  80.                 break;
  81.        case 0:  if (!visitor.fontTable(start)) return 0;
  82.                 break;
  83.        case 9:  if (!visitor.textAreaObject(start)) return 0;
  84.                 break;
  85.        case 10: if (!visitor.textColumnObject(start)) return 0;
  86.                 break;
  87.        case 11: if (!visitor.optionsObject(start)) return 0;
  88.                 break;
  89.       default:  if (!visitor.unknownObject(start)) return 0;
  90.     }
  91.     start=next;
  92.   };
  93.   return 1;
  94. };  
  95.  
  96.